package Meituan;

/**
 * @author: leiwenkang02@meituan.com
 * @date: 2019/3/14
 * @time: 19:59
 */
public class ThreadLocalTest {

    ThreadLocal<String> nameLocal = new ThreadLocal<String>();
    ThreadLocal<Integer> ageLocal = new ThreadLocal<Integer>();


    public void set() {
        ageLocal.set(18);
        nameLocal.set("白嘉安");
    }

    public Integer getAge() {
        return ageLocal.get();
    }

    public String getName() {
        return nameLocal.get();
    }

    public static void main(String[] args) throws InterruptedException {
        final ThreadLocalTest test = new ThreadLocalTest();


        test.set();
        System.out.println(test.getAge());
        System.out.println(test.getName());


        Thread thread1 = new Thread(){
            public void run() {
                test.set();
                System.out.println(test.getAge());
                System.out.println(test.getName());
            };
        };
        thread1.start();
        thread1.join();

        System.out.println(test.getAge());
        System.out.println(test.getName());
    }
}
